package com.example.lib.server;

import com.example.lib.userinfo.FileUserInfoDAOImpl;
import com.example.lib.userinfo.UserInfo;

import java.util.List;

public class Login {

    public static String login(String username, String password) {

        FileUserInfoDAOImpl userInfoDAO = new FileUserInfoDAOImpl();

        List<UserInfo> userInfoList = userInfoDAO.getAllUserInfo();

        if (userInfoList == null) {
            return "fail";
        }

        for (UserInfo userInfo: userInfoList) {
            System.out.println(userInfo.getName() + userInfo.getPassword());
        }
        for (UserInfo userInfo: userInfoList) {
            if (userInfo.getName().equals(username) &&
                    userInfo.getPassword().equals(password)) {
                //登录成功
                return "success";
            } else if (userInfo.getName().equals(username) &&
                    !userInfo.getPassword().equals(password)) {
                //密码不正确
                return "incorrect";
            } else if (!userInfo.getName().equals(username) &&
                    userInfo.getPassword().equals(password)) {
                //用户名不正确
                return "incorrect";
            }
        }
        return "notexist";
    }
}


